package dao;

import entity.Damn;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: DELL
 * @Since: 2024/9/26 10:33
 * @Description:
 */
public class DamnDao extends BaseDao{
    public List<Damn> getAll(){
        String sql="SELECT * FROM damn";
        ResultSet rs=executeQuery(sql);
        List<Damn> damns=new ArrayList<>();
        try {
            while (rs.next()){
                Damn damn=new Damn();
                damn.setId(rs.getInt("id"));
                damn.setName(rs.getString("name"));
                damn.setAge(rs.getInt("age"));
                damn.setGender(rs.getString("gender"));
                damn.setMajor(rs.getString("major"));
                damns.add(damn);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            closeAll(connection,pstmt,rs);
        }
        return damns;
    }

    public int addStudent(Damn damn){
        String sql="INSERT INTO damn (name,age,gender,major) VALUES(?,?,?,?)";
        Object params[]={damn};
       int hangshu= executeUpdate(sql,params);
       return hangshu;
    }
    public int UpdateStudent(Damn damn){
        String sql="UPDATE damn SET `name`=?,age=?,gender=?,major=? WHERE id=?";
        Object params[]={damn};
        int hangshu= executeUpdate(sql,params);
        return hangshu;
    }
    public int DeleteStudent(Damn damn){
        String sql="INSERT INTO damn (name,age,gender,major) VALUES(?,?,?,?)";
        Object params[]={damn};
        int hangshu= executeUpdate(sql,params);
        return hangshu;
    }





}
